<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro" >
<meta charset="utf-8">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title></title>
    <meta name="keywords" content="">
    <meta name="description" content="">
    <link rel="shortcut icon" href="favicon.ico">
    <link th:href="@{/css/bootstrap.min.css}" rel="stylesheet"/>
    <link th:href="@{/css/layui.css}" rel="stylesheet" >
    <link th:href="@{/css/font-awesome.css}" rel="stylesheet"/>
    <!-- bootstrap-table 表格插件样式 -->
    <link th:href="@{/ajax/libs/bootstrap-table/bootstrap-table.min.css}" rel="stylesheet"/>
    <link th:href="@{/ajax/libs/jqTreeGrid/jquery.treegrid.css}" rel="stylesheet"/>
    <link th:href="@{/css/animate.css}" rel="stylesheet"/>
    <link th:href="@{/css/style.css}" rel="stylesheet"/>
    <link th:href="@{/css/checkbox.css}" rel="stylesheet"/>
    <link th:href="@{/ajax/libs/select/select2.css}" rel="stylesheet"/>
    <link th:href="@{/ruoyi/css/ry-ui.min.css}" rel="stylesheet"/>
    <!-- Data Tables -->
    <link th:href="@{/css/plugins/dataTables/dataTables.bootstrap.css}" rel="stylesheet">
    <link href="/ajax/libs/jquery-layout/jquery.layout-latest.css" th:href="@{/ajax/libs/jquery-layout/jquery.layout-latest.css}" rel="stylesheet"/>
    <link href="/ajax/libs/jquery-ztree/3.5/css/metro/zTreeStyle.css" th:href="@{/ajax/libs/jquery-ztree/3.5/css/metro/zTreeStyle.css}" rel="stylesheet"/>
</head>
<body class="gray-bg">
<div class="container-div ui-layout-center">
    <div class="row">
        <div class="col-sm-12 select-info">
            <form id="user-form">
                <input type="hidden" id="deptId" name="deptId">
                <input type="hidden" id="parentId" name="parentId">
                <div class="select-list gd">
                    <ul>
                        <li>
                            角色名称：<input type="text" name="realName"/>
                        </li>
                        <li>
                            <a class="btn btn-primary btn-rounded btn-sm" onclick="searchUser()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                            <!--<a class="export-excel btn btn-success btn-rounded btn-sm"  id="btn_export"><i class="fa fa-download"></i>&nbsp;下载</a>-->
                        </li>
                    </ul>
                </div>
            </form>
        </div>
        <div class="col-sm-12 select-info table-bordered">
            <div class="btn-group hidden-xs" id="toolbar" role="group" style="margin-bottom: 5px ;margin-top: 10px">
                <a  class="btn btn-outline btn-success btn-rounded"  onclick="addUser()">
                    <i class="fa fa-plus"></i> 新增
                </a>
                <a class="btn btn-outline btn-danger btn-rounded" onclick="deleteSelectedRole()">
                    <i class="fa fa-trash-o"></i> 删除
                </a>
            </div>
            <table id="tb_departments">
            </table>
            <input name="editstatus"  type="hidden"  id="editstatus" />
        </div>
    </div>
</div>
</div>
</div>
</div>
</div>
<script th:src="@{/js/jquery.min.js}"></script>
<script th:src="@{/js/bootstrap.min.js}"></script>
<!-- bootstrap-table 表格插件 -->
<script th:src="@{/ajax/libs/bootstrap-table/bootstrap-table.min.js}"></script>
<script th:src="@{/ajax/libs/bootstrap-table/locale/bootstrap-table-zh-CN.min.js}"></script>
<script th:src="@{/ajax/libs/bootstrap-table/extensions/mobile/bootstrap-table-mobile.min.js}"></script>
<script th:src="@{/ajax/libs/bootstrap-table/extensions/toolbar/bootstrap-table-toolbar.min.js}"></script>
<!-- jquery-export 表格导出插件 -->
<script th:src="@{/ajax/libs/bootstrap-table/extensions/export/bootstrap-table-export.js}"></script>
<script th:src="@{/ajax/libs/bootstrap-table/extensions/export/tableExport.js}"></script>
<!-- Data Tables -->
<script th:src="@{/js/plugins/dataTables/jquery.dataTables.js}"></script>
<script th:src="@{/js/plugins/dataTables/dataTables.bootstrap.js}"></script>
<script th:src="@{/js/plugins/jeditable/jquery.jeditable.js}"></script>
<script th:src="@{/js/plugins/layer/laydate/laydate.js}"></script>
<script th:src="@{/ajax/libs/jquery-layout/jquery.layout-latest.js}"></script>
<script th:src="@{/ajax/libs/jquery-ztree/3.5/js/jquery.ztree.all-3.5.js}"></script>
<script th:src="@{/ajax/libs/layer/layer.min.js}"></script>
<script th:src="@{/ajax/libs/layui/layui.js}"></script>
<script th:src="@{/ruoyi/js/common.js?v=2.2.0}"></script>
<script th:src="@{/ruoyi/js/yuyu-ui.min.js?v=2.2.0}"></script>
<script>
    $(function () {
        initTable();
    });
    function refreshTable() {
        $("#tb_departments").bootstrapTable('refresh',{url : "/role/list"});
    }
    function initTable() {
        //1.初始化Table
        var oTable = new TableInit();
        oTable.Init();

        //2.初始化Button的点击事件
        var oButtonInit = new ButtonInit();
        oButtonInit.Init();
    }
    var TableInit = function () {
        var oTableInit = new Object();
        //初始化Table
        oTableInit.Init = function () {
            $('#tb_departments').bootstrapTable({
                url: '/role/list',         //请求后台的URL（*）
                method: 'get',                      //请求方式（*）
                toolbar: '#toolbar',                //工具按钮用哪个容器
                striped: true,                      //是否显示行间隔色
                cache: false,                       //是否使用缓存，默认为true，所以一般情况下需要设置一下这个属性（*）
                pagination: true,                   //是否显示分页（*）
                sortName: "id",
                sortable: false,                     //是否启用排序
                sortOrder: "asc",                   //排序方式
                queryParams: oTableInit.queryParams,//传递参数（*）
                sidePagination: "server",           //分页方式：client客户端分页，server服务端分页（*）
                pageNumber:1,                       //初始化加载第一页，默认第一页
                pageSize: 10,                       //每页的记录行数（*）
                pageList: [10, 25, 50, 100],        //可供选择的每页的行数（*）
                search: false,                       //是否显示表格搜索，此搜索是客户端搜索，不会进服务端，所以，个人感觉意义不大
                strictSearch: true,
                showColumns: true,                  //是否显示所有的列
                showRefresh: true,                  //是否显示刷新按钮
                minimumCountColumns: 2,             //最少允许的列数
                 clickToSelect: true,                //是否启用点击选中行
                // height: 500,                        //行高，如果没有设置height属性，表格自动根据记录条数觉得表格高度
                uniqueId: "id",                     //每一行的唯一标识，一般为主键列
                showToggle:true,                    //是否显示详细视图和列表视图的切换按钮
                cardView: false,                    //是否显示详细视图
                detailView: false,                   //是否显示父子表
                columns: [{
                    checkbox: true
                }, {
                    field: 'roleId',
                    title: '角色编号',
                    sortable: true
                },{
                    field: 'roleDescription',
                    title: '角色名称'
                }, {
                    field: 'role',
                    title: '权限字符'
                }, {
                    field: 'parentRoleName',
                    title: '上级角色'
                },{
                        field: 'Button',
                        title: '操作',
                        align: 'center',
                        events: operateEvents,
                        formatter: Oper
                    }
                    ,],
                showExport:true,              //是否显示导出按钮(此方法是自己写的目的是判断终端是电脑还是手机,电脑则返回true,手机返回falsee,手机不显示按钮)
                exportDataType: "all",              //basic', 'all', 'selected'.
                exportTypes:[ 'excel','doc','xlsx','csv', 'txt', 'sql' ],	    //导出类型
                // exportButton: $('#btn_export'),     //为按钮btn_export  绑定导出事件  自定义导出按钮(可以不用)
                exportOptions:{
                    ignoreColumn: [0,8],            //忽略某一列的索引
                    fileName: '员工信息表',              //文件名称设置
                    worksheetName: 'Sheet1',          //表格工作区名称
                    tableName: '数据表',
                    excelstyles: ['background-color', 'color', 'font-size', 'font-weight'],
                    //onMsoNumberFormat: DoOnMsoNumberFormat
                }
            });
        };
        //得到查询的参数
        oTableInit.queryParams = function (params) {
            var temp = {   //这里的键的名字和控制器的变量名必须一直，这边改动，控制器也需要改成一样的
                limit: params.limit,   //页面大小
                offset: params.offset,  //页码
                departmentname: $("#txt_search_departmentname").val(),
                statu: $("#txt_search_statu").val(),
                search:params.search
            };
            return temp;
        };
        return oTableInit;
    };
    function Oper(){
        return [
            '<button id="TableEditor"  type="button" class="btn btn-success btn-xs"><i class="fa fa-edit"></i>&nbsp编辑</button>',
            '&nbsp<button id="TableAuthority" type="button" class="btn btn-primary btn-xs "><i class="  fa fa-check-square-o"></i>&nbsp权限</button>',
            '&nbsp<button id="TableDelete" type="button" class="btn btn-danger btn-xs"><i class="fa fa-remove"></i>&nbsp删除</button>'
        ].join("")
    }
    window.operateEvents = {
        "click #TableAuthority": function (e ,value, row, index) {
            var url = '/role/authority/'+row.roleId;
            $.modal.open("角色权限", url, '800', '480');
        },
        "click #TableEditor": function (e ,value, row, index) {
            var url = '/role/edit/'+row.roleId;
            $.modal.open("编辑角色", url, '800', '480');
        },
        "click #TableDelete": function (e ,value, row, index) {
            layer.confirm('确定删除这个角色信息吗?', {
                btn: ['确定','取消'] //按钮
            }, function(){
                var json={"roleId":row.roleId};
                $.ajax({
                    url: '/role/delete',
                    type : "post",
                    data: JSON.stringify(json),
                    dataType: 'json',
                    contentType:"application/json",
                    success: function (data) {
                        if (data.code==200){
                            $("#tb_departments").bootstrapTable('refresh',{url : "/role/list"});
                            layer.msg('删除成功', {icon: 1});
                        }
                    }
                });

            }, function(){});
        }
    }
    var ButtonInit = function () {
        var oInit = new Object();
        var postdata = {};
        oInit.Init = function () {
            //初始化页面上面的按钮事件
        };
        return oInit;
    };
    $('body').layout({ west__size: 185 });
    /* 查询**/
    function searchUser() {
        var startDate = $("input[name='params[beginTime]']").val();
        var endDate = $("input[name='params[endTime]']").val();
        var realName = $("input[name='realName']").val();
        var id = $("input[name='id']").val();
        if ($("#status option:selected").val()  == '所有'){
            var  status=null;
        }else {
            var   status =  $("#status option:selected").val() == "在职" ? 1 : 2;
        }
        var json ={
            "id": id,
            "realName": realName,
            "status": status,
            "startDate": startDate,
            "endDate": endDate
        }
        $("#tb_departments").bootstrapTable('refresh', {
            url: "/user/searchuser", //重设数据来源
            query: json//传到后台的参数
        });
    }
    function addUser() {
        var url = '/role/add';
        $.modal.open("添加员工", url, '800', '480');
    }
    /*用户管理-重置密码*/
    function deleteSelectedRole() {
        var a= $("#tb_departments").bootstrapTable('getSelections');
        var json=JSON.stringify(a);
        if (a == ""){
            layer.alert('请至少选择一条记录!', {
                icon: 3
            })
        }else {
            layer.confirm('确定删除这'+a.length+'个员工信息吗?', {
                btn: ['确定','取消'] //按钮
            }, function(){
                $.ajax({
                    url: '/role/deleteall',
                    type: 'post',
                    data: json,
                    dataType: 'json',
                    contentType:"application/json",
                    success: function (data) {
                        if (data.code==200) {
                            $("#tb_departments").bootstrapTable('refresh',{url : "/role/list"});
                            layer.msg('删除成功', {icon: 1});
                        }
                    }
                });
            }, function(){});
        }

    }
</script>
</body>
</html>